package com.ads.proplan.activity;

import com.ads.proplan.R;
import com.ads.proplan.control.FaseControl;
import com.ads.proplan.db.entity.Fase;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.UiThread;
import com.googlecode.androidannotations.annotations.ViewById;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

@EActivity(R.layout.activity_trophy)
public class TrophyActivity extends Activity{
	
	@ViewById(R.id.trophy_image)
	public ImageView doctorImageView;
	
	@ViewById(R.id.trophy_image_like)
	public ImageView likeImageView;
	
	@ViewById(R.id.trophy_view)
	public RelativeLayout view;

	private FaseControl control;

	@Override
	protected void onStart() {
		super.onStart();
		control = FaseControl.getInstance();
		selectModelo();	
		checkNextScreenFase();
	}

	@UiThread(delay=500)
	public void selectModelo() {
		likeImageView.setVisibility(View.VISIBLE);
		if(((FaseControl) control).isQuestionResult()){
			view.setBackgroundColor(Color.parseColor("#00FF00"));
		}else{
			likeImageView.setImageResource(R.raw.dislike);
			view.setBackgroundColor(Color.parseColor("#FF0000"));
		}
	}

	private void checkNextScreenFase() {
		ifNextStage();
	}
	
	private boolean chekGameOver() {
		boolean retorno = false;
		if(control.getQuestionCorrectNumber() >= (control.getNumberQuestionsStage()/3)){
			//TODO Mudar de Fase
			if(control.getJogadorEntity().getFase() == 3){
				retorno = true;	
			}
		}
		return retorno;
	}
	
	@UiThread(delay=1000)
	public void ifNextStage() {
		//TODO Mudar de Fase
		if(control.getJogadorEntity().getFase() == 1){
			control.getJogadorEntity().setFase(control.getJogadorEntity().getFase()+1);
			control.setEstadoFase(2, Fase.PERSONAGEMNELTRO);
			CharacterActivity_.intent(this).start();
		}else if(control.getJogadorEntity().getFase() == 2){
			control.getJogadorEntity().setFase(control.getJogadorEntity().getFase()+1);
			control.setEstadoFase(3, Fase.ATENDENTEFINAL);
			CharacterActivity_.intent(this).start();
		}else if(control.getJogadorEntity().getFase() == 3){
			SharedPreferences prefs = this.getSharedPreferences(QuestionActivity.TAG_SharedP, Context.MODE_PRIVATE);
			prefs.edit().putBoolean(EndTimeActivity.TAG_DESAFIO, true).commit();
			control.setEstadoFase(1, Fase.ATENDENTEINICIAL);
			GameOverActivity_.intent(this).start();
		}
		control.restartControl();
		control.closeControl();
		finish();
	}
	
}
